<template>
  <orh-table pages :pageDate="pageDate" @on-page-change="queryData">
        <Table :columns="columns1" :data="tealeaveList" slot="table" :loading="tableload"  highlight-row ref="currentRowTable"></Table>
    </orh-table>
</template>

<script>
export default {
    components: {
    },
    name: 'leave-mystudentleave',
        data(){
            return {
                pageDate: {
                    total: 0,
                    current_page: 1,
                    per_page: 1
                },
                tealeaveList:[],
                tableload:true,
                listurl:'api/leave/v1/student_leave/my_leave?page=',
                columns1: [
                    {
                        title: '学生姓名',
                        render: (h, params) => {
                            return h('div', params.row.student!=null?params.row.student.student_name.zh:'');
                        }
                    },
                    {
                        title: '请假种类',   
                        render: (h, params) => {
                            return h('div', params.row.leave_classifications.dictionary_name.zh);
                        }
                    },
                    {
                        title: '请假类型',   
                        render: (h, params) => {
                            return h('div', params.row.student_leave_kinds.dictionary_name.zh );
                        }
                    },
                    {
                        title: '请假开始时间',       
                        align: 'center',
                        key:'start_time',
                    },
                    {
                        title: '请假结束时间',       
                        align: 'center',
                        key:'end_time',
                    },
                ],         
            }
        },
        
        methods: {           
            /************************************************************
             * 获取我的学生请假列表
             ************************************************************/
            queryData(index){
                this.$http.get(`api/leave/v1/student_leave/my_leave?page=${index}`).then(val=>{   
                    this.tealeaveList = val.data
                    if(val.pages!=null){                        
                        this.pageDate.total=val.pages.total
                        this.pageDate.per_page=val.pages.per_page
                        this.pageDate.current_page=val.pages.current_page
                    }
                    this.tableload = false                  
                }).catch(err => {
                    if (err.code && err.code == 422) {
                        this.$Message.error(err.message);
                    }
                    this.tableload = false
                })
            },
        },
        mounted(){
            this.queryData(this.pageDate.current_page);
        },
}
</script>
